/**
 * 详情对话框
 */
var UserGradeInfoDlg = {
    data: {
        payRate1: "",
        payRate2: "",
        payRate3: "",
        payRateMax: "",
        upRate1: "",
        upRate2: "",
        upRate3: "",
        upRateMax: "",
        createTime: "",
        updateTime: "",
        deleteFlag: "",
        icon: "",
        upScore: "",
        addRate: ""
    }
};

layui.use(['form', 'upload', 'admin', 'ax'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var upload = layui.upload;
    //让当前iframe弹层高度适应
    admin.iframeAuto();

    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/userGrade/detail?gradeId=" + Feng.getUrlParam("gradeId"));
    var result = ajax.start();
    form.val('userGradeForm', result.data);

    if (result.data.icon != null) {
        $("#iconView").attr("src", Feng.ctxPath + "/system/previewImgage?fileId=" + result.data.icon);
    }
    form.render('select');
    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/userGrade/editItem", function (data) {
            Feng.success("更新成功！");
            window.location.href = Feng.ctxPath + '/userGrade'
        }, function (data) {
            Feng.error("更新失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    //返回按钮
    $("#backupPage").click(function () {
        window.location.href = Feng.ctxPath + '/userGrade'
    });
    upload.render({
        elem: '#imgHead'
        , url: Feng.ctxPath + '/system/upload'
        , before: function (obj) {
            obj.preview(function (index, file, result) {
                $('#iconView').attr('src', result);
            });
        }
        , done: function (res) {
            $("#icon").val(res.data.fileId);
            /*var ajax = new $ax(Feng.ctxPath + "/system/updateAvatar", function (data) {
                Feng.success(res.message);
            }, function (data) {
                Feng.error("修改失败!" + data.responseJSON.message + "!");
            });
            ajax.set("fileId", res.data.fileId);
            ajax.start();*/
        }
        , error: function () {
            Feng.error("上传头像失败！");
        }
    });
});
